package com.itheima.app.controller;


import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import com.itheima.vo.PageBeanVo;
import com.itheima.vo.SettingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;

    //查询通用设置
    @GetMapping("/users/settings")
    public SettingVo findSetting() {
        return settingManager.findSetting();
    }

    //设置陌生人问题
    @PostMapping("/users/questions")
    public void saveOrUpdateQuestion(@RequestBody Map<String,String> map){

        //接受参数（content：陌生人问题的值）
        String content = map.get("content");

        //调用manager
        settingManager.saveOrUpdateQuestion(content);
    }

    //设置通知
    @PostMapping("/users/notifications/setting")
    public void saveOrUpdateNotification(@RequestBody Notification notificationParam){

        //形参已经接受了参数，直接调用manager
        settingManager.saveOrUpdateNotification(notificationParam);
    }

    //分页查询黑名单列表
    @GetMapping("/users/blacklist") //将请求参数绑定到你控制器的方法参数上（是springmvc中接收普通参数的注解）
    public PageBeanVo findBlackList(@RequestParam(value = "page",defaultValue = "1")Integer pageNum,
                                    @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize)
    {
        //调用manager
        return settingManager.findBlackList(pageNum,pageSize);
    }

    //移除黑名单
    @DeleteMapping("/users/blacklist/{uid}")  //这里yapi中的写法是/users/blacklist/:uid
    public void deleteBlackList(@PathVariable("uid")  Long blackUserId){

        settingManager.deleteBlackList(blackUserId);

    }
}
